package com.example.chartroom.controller;

import com.example.chartroom.model.Message;
import com.example.chartroom.model.MessageMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RestController;


import java.util.Collections;
import java.util.List;

@RestController

public class MessageController {
    @Autowired
    private MessageMapper messageMapper;

    @GetMapping("/message")
    public Object getMessage(int sessionId){
        List<Message> messages = messageMapper.getMessagesBySessionId(sessionId);
        //数据库查询的结果是按时间降序的,而实际界面上是升序的结果
        Collections.reverse(messages);
        return messages;
    }
}
